package com.lanmaoly.cunzheng.enumDemo;

import java.util.Arrays;
import java.util.List;

public class EnumDemo {

	// ����ö������
	Day[] days = new Day[] { Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY, Day.THURSDAY, Day.FRIDAY, Day.SATURDAY, Day.SUNDAY };

	Day[] days2 = { Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY, Day.THURSDAY, Day.FRIDAY, Day.SATURDAY, Day.SUNDAY };

	Day[] days3 = Day.values();

	public static void main(String[] args) {
		/*
		 * Day day = Day.MONDAY; if (day.equals(Day.MONDAY)) {
		 * System.out.println(day); }
		 */
		EnumDemo demo = new EnumDemo();
		// demo.days();
		 demo.arrayTest();
		// demo.test2();
//		demo.printName(Day.MONDAY);
	}
	
	public void printName(Day day){
		switch (day) {
		case MONDAY:
			System.out.println("��һ");
			break;
		case TUESDAY:
			System.out.println("�ܶ�");
			break;
		case WEDNESDAY:
			System.out.println("����");
			break;
		case THURSDAY:
			System.out.println("����");
			break;
		default:
			System.out.println("����");
			break;
		}
	}
	
	public void test2(){
		// ����ת��Enum
		Enum<?> e = Day.MONDAY;
		Class<?> cls = e.getDeclaringClass();
		if (cls.isEnum()) {
			Day[] day = (Day[]) cls.getEnumConstants();
			System.out.println(Arrays.toString(day));
		}
	}

	public void arrayTest() {
		// values()������valueOf(String
		// name)�����Ǳ��������ɵ�static��������˴�ǰ��ķ����У�
		// ��Enum���в�û����values()��������valueOf()���������г��ֵģ�
		// ֻ�������������ɵ�valueOf()�����贫��һ��name��������Enum�Դ��ľ�̬����valueOf()����Ҫ��������������
		// ��ǰ�淴�����Ĵ�����Կ��������������ɵ�valueOf�������ջ��ǵ�����Enum���valueOf����������ͨ����������ʾ���������������ã�
		List<Day> list = Arrays.asList(days);
		System.out.println("list:" + list);
		System.out.println("day1:" + Arrays.toString(days));
		System.out.println("day2:" + Arrays.toString(days2));
		System.out.println("day3:" + Arrays.toString(days3));

		Day day = Day.valueOf("MONDAY");
		System.out.println("day:" + day);
	}

	public void days() {
		for (int i = 0; i < days.length; i++) {
			System.out.println("day[" + i + "].ordinal():" + days[i].ordinal());
		}

		System.out.println("-------------------------------------");
		// ͨ��compareTo�����Ƚ�,ʵ�������ڲ���ͨ��ordinal()ֵ�Ƚϵ�
		System.out.println("days[0].compareTo(days[1]):" + days[0].compareTo(days[1]));
		System.out.println("days[0].compareTo(days[1]):" + days[0].compareTo(days[2]));

		// ��ȡ��ö�ٶ����Class��������,��ȻҲ����ͨ��getClass����
		Class<?> clazz = days[0].getDeclaringClass();
		System.out.println("clazz:" + clazz);

		System.out.println("-------------------------------------");

		// name()
		System.out.println("days[0].name():" + days[0].name());
		System.out.println("days[1].name():" + days[1].name());
		System.out.println("days[2].name():" + days[2].name());
		System.out.println("days[3].name():" + days[3].name());

		System.out.println("-------------------------------------");

		System.out.println("days[0].toString():" + days[0].toString());
		System.out.println("days[1].toString():" + days[1].toString());
		System.out.println("days[2].toString():" + days[2].toString());
		System.out.println("days[3].toString():" + days[3].toString());

		System.out.println("-------------------------------------");

		Day d = Enum.valueOf(Day.class, days[0].name());
		Day d2 = Day.valueOf(Day.class, days[0].name());
		System.out.println("d:" + d);
		System.out.println("d2:" + d2);
	}

}
